package dao.ebean;

import com.avaje.ebean.Ebean;
import dao.common.ShopOwnersRepository;
import models.ShopOwner;

public class ShopOwnersRepositoryImpl implements ShopOwnersRepository {
    public void add(ShopOwner user) {
        Ebean.save(user);
    }

    public boolean isValid(String email, String password) {
        ShopOwner owner = Ebean.find(ShopOwner.class)
                .where("email = :email and password = :password")
                .setParameter("email", email)
                .setParameter("password", password).findUnique();
        return owner != null;
    }

    public ShopOwner getByEmail(String email) {
        return Ebean.find(ShopOwner.class)
                .where("email = :email")
                .setParameter("email", email).findUnique();
    }

    public void delete(String email) {
        Ebean.createUpdate(ShopOwner.class, "delete from ShopOwner where email = :email")
                .setParameter("email", email)
                .execute();
    }
}
